<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page
	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@page import="cn.hn.tx.rebot.blog.service.ICrawlBlogService"%>
<%@page import="cn.hn.tx.rebot.blog.service.IRebotBlogService"%>
<%@page import="cn.hn.tx.rebot.blog.model.Blog"%>
<%@page import="cn.hn.tx.rebot.task.job.TaskJob_CrawlBlog"%>
<%@page import="cn.hn.comm.Tools"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'index.jsp' starting page</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	</head>

	<body>
		first crawl blog
		<br>
		<%
			Object obj = getServletContext();
			//System.out.println(obj);
			ApplicationContext context = WebApplicationContextUtils
					.getWebApplicationContext(getServletContext());

			ICrawlBlogService crawlService = (ICrawlBlogService) context
					.getBean("CrawlService_SinaEladies");

			IRebotBlogService rebotBlogService = (IRebotBlogService) context
					.getBean("RebotBlogService");

			/*
			Blog blog2=crawlService.getBlog("http://club.eladies.sina.com.cn/thread-4195116-1-1.html");
			rebotBlogService.insertRebotWriteBlog(blog2.getTitle(), blog2.getContent(),
									blog2.getUrl(), 0, new Date(), null, 0);
			
			if(true)
			{
				return;
			}
			 */

			int crawlStartPage = 1;
			int crawlEndPage = 78;
			String url_blogListPrefix = "http://club.eladies.sina.com.cn/forum-25-";
			String url;

			//列表主页抓取
			for (int i = crawlStartPage; i <= crawlEndPage; i++) {
				//列表地址
				url = url_blogListPrefix + i + ".html";
				System.out.println("日志列表抓取:"+url+"-------------------------------------------------------------------------");	
				//获取列表中的日志
				List<Blog> listBlogs = crawlService.getBlogs(url);
				if (listBlogs != null) {
					if (listBlogs != null && listBlogs.size() > 0) {
						//迭代日志
						Iterator<Blog> iterBlog = listBlogs.iterator();
						while (iterBlog.hasNext()) {
							Blog blog = iterBlog.next();
							//日志写入
							rebotBlogService.insertRebotWriteBlog_HandleHref("小三","http://www.tianxin007.com",blog
									.getTitle(), blog.getContent(), blog
									.getUrl(), 0, Tools.getCurDate(null), null, 0);
						}
					}
				}
			}
		%>
	</body>
</html>
